package szf.im.client.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author shizhanfu
 * 普通类获取spring管理的bean对象
 */
@Component
public class SpringUtil implements ApplicationContextAware {
    private static ApplicationContext _applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        _applicationContext = applicationContext;
    }
    private static ApplicationContext getApplicationContext(){
        return _applicationContext;
    }
    public static Object GetBean(String name){
        return getApplicationContext().getBean(name);
    }
    public static <T> T GetBean(Class<T> clazz){
        return getApplicationContext().getBean(clazz);
    }
}
